package logic

import (
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"
	"github.com/zeromicro/go-zero/core/logx"
)

type RealNameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealNameLogic {
	return &RealNameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealNameLogic) RealName(req *types.RealNamerequest) (resp *types.Response, err error) {
	name, err := l.svcCtx.Userrpc.RealName(l.ctx, &user.RealNameRequest{
		UserId:   int64(req.UserId),
		RealName: req.RealName,
		IdCard:   req.IdCard,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "用户实名失败",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Code:    200,
		Message: "用户实名成功",
		Data:    name,
	}, nil
}
